﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Windows.Threading;
using System.IO;

namespace TouchExplorer
{
    /// <summary>
    /// Interaction logic for TouchFileDisplay.xaml
    /// </summary>
    public partial class TouchFileDisplay : Grid
    {
        public TouchFileDisplay()
        {
            InitializeComponent();
            MouseUp += new MouseButtonEventHandler(TouchFileDisplay_MouseUp);
            Loaded += (sender, arg) =>
            {
                var file = DataContext as TouchFile;
                Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
                    {
                        ImgElement.Source = file.Image;
                        System.Windows.Forms.Application.DoEvents();
                    }));
                
            };
        }

        void TouchFileDisplay_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var file = DataContext as TouchFile;
            if (file != null)
            {
                file.IsSelected = !file.IsSelected;
            }
        }

        private void BtnStart_Click(object sender, RoutedEventArgs e)
        {
            var file = DataContext as TouchFile;
            if (file != null)
            {
                file.Run();
            }
        }

        private void BtnFav_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Remove from favorite ?", "Favorites", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                var file = DataContext as TouchFile;
                App.Current.Favorites.Remove(file);
            }
        }

        /*
         
         Code to cut files in clipboard :
         byte[] moveEffect = new byte[] {2, 0, 0, 0}; //put 5 instead of 2 to copy files
         MemoryStream dropEffect = new MemoryStream();
         dropEffect.Write(moveEffect, 0, moveEffect.Length);
         DataObject data = new DataObject();
         data.SetFileDropList(files);
         data.SetData("Preferred DropEffect", dropEffect);
         Clipboard.Clear();
         Clipboard.SetDataObject(data, true);
         
         */
    }
}
